﻿<#include "include/_meta.html">
<title>车辆列表</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 车辆管理<span class="c-gray en">&gt;</span> 车辆记录列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="text-c">
        <input type="text" class="input-text" style="width:250px" placeholder="车牌号" id="likecarcode" name="">
        车辆状态：
        <select id="carstate">
            <option value=0>车辆状态</option>
            <option value=1>待审核</option>
            <option value=2>不合格</option>
            <option value=3>已报废</option>
            <option value=4>已删除</option>
            <option value=5>待上架</option>
            <option value=6>待租赁</option>
            <option value=7>自用中</option>
            <option value=8>维修中</option>
            <option value=9>保养中</option>
            <option value=10>年检中</option>
        </select>
        
        <button type="submit" class="btn btn-success" id="searchCar" name=""><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> <a href="javascript:;" onclick="car_add('添加车辆','car-adds.html','800','500')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加车辆</a></span> <span class="r">共有数据：<strong id="pageTotal">54</strong> 条</span> </div>
    <table id="carTable" class="table table-border table-bordered table-bg table-hover">
        <thead>
            <tr>
                <th scope="col" colspan="9">账户列表</th>
            </tr>
            <tr class="text-c">
                <th width="25"><input type="checkbox" name="caritem" value=""></th>
                <!--<th width="40">ID</th>-->
                <th width="150">车型</th>
                <th width="150">车牌</th>
                <th width="150">日租金</th>
                <th width="150">租赁点</th>
                <th width="130">所属城市</th>
                <th width="100">状态</th>
                <th width="100">操作</th>
            </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
</div>

<#include "include/_footer.html">

<script type="text/javascript">

$(function(){

    initTable();
  
});


var initTable = function(){

$('#carTable').dataTable( {
        "processing": false,
        "serverSide": true,
        "bSort": false,
        "bFilter":false,
        "bLengthChange":false,
        "iDisplayLength":10,
        "bRetrieve":true,
        "ajax": {
            "url": "/car",
            "data":function(d){
                d.carcode = $('#likecarcode').val();
                d.carstate = $('#carstate').val();                
            },
            "type": "get"
        },
        "columns": [
            { "data": "" },
            { "data": "cartype" },
            { "data": "carcode" },
            { "data": "dayprice" },
            { "data": "deptname" },
            { "data": "carcity" },
            { "data": "carstate" },
            { "date": ""}
        ],
        "columnDefs": [
            {
                  "targets": [0],
                  "data": "carid",
                  "render": function(data, type, full) {
                    return "<input type='checkbox' value=" + full.carid + " name='caritem'>";
                    //return full.id+"";
                  }
            },
            {"targets": [7],
                  "data": "carid",
                  
                  "render": function(data, type, full) {
                  
                            var action_isabled = "<a style='text-decoration:none' onClick=\"admin_start(this,'"+full.id+"')\" href=\"javascript:;\" title=\"启用\"><i class=\"Hui-iconfont\">&#xe615;</i></a>";
                            if(full.isabled == '1'){
                                action_isabled = "<a style='text-decoration:none' onClick=\"admin_stop(this,'"+full.id+"')\" href=\"javascript:;\" title=\"停用\"><i class=\"Hui-iconfont\">&#xe631;</i></a>";
                            }
                            var action_edit    = "<a title=\"编辑\" href=\"javascript:;\" onclick=\"car_edit('车辆信息编辑','/car-edit?carid="+full.carid+"','2','800','500')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6df;</i></a>";
                            var action_del     = "<a title=\"删除\" href=\"javascript:;\" onclick=\"car_del(this,'"+full.carid+"')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6e2;</i></a>";
                  
                            return action_isabled+" "+action_edit+" "+action_del;
                }
            }           
        ],
        "fnRowCallback" : function(nRow, aData, iDisplayIndex) { 
                        nRow.className="text-c";       
                        if (aData.isabled == '1') {
                            $('td:eq(6)', nRow).html("<span class=\"label label-success radius\">已启用</span>");  
                        }  
                        if (aData.isabled == '0') {
                            $('td:eq(6)', nRow).html("<span class=\"label radius\">已停用</span>");    
                        } 
                        $('td:eq(6)', nRow).addClass("td-status");  
                        $('td:eq(7)', nRow).addClass("td-manage");                     
                        return nRow;  
         },
        "fnDrawCallback": function(oSettings) {
              //获取后台方式 直接可以拿到json 之后进行处理
              var json=jQuery.parseJSON(oSettings.jqXHR.responseText);  
              $("#pageTotal").html(json.recordsTotal);
        }
  
        
    })

}


$("#searchCar").click(function() {
        var i_data = $('#likecarcode').val();
        console.log("carstate:"+ $('#carstate').val());       
        $("#carTable").dataTable().fnClearTable();
        initTable();
});



var datadel = function(){
    
    //判断选择项是否为空
    var checkedNum = $("input[name='caritem']:checked").length;
    if(checkedNum==0){
    
        layer.msg('请选中要删除的列表项!',{icon: 5,time:1000});
        return;
    }
    //获取选择项的值
    var checkedVal = "";
    $("input[name='caritem']:checked").each(function(){  
        checkedVal+=$(this).val()+","; 
        
    });
    
    var itemsTipStr = "这条记录";
    if(checkedNum>1){
        itemsTipStr = "这些选项";
    }
    
    layer.confirm('确认要删除'+itemsTipStr+'吗？',function(){
        //此处请求后台程序，下方是成功后的前台处理……
        $.ajax({
           type: "post",
           url: "/delCars",
           data: "carid="+checkedVal,
           success: function(msg){
                   
                layer.msg('已删除!',{icon: 5,time:1000});
                
                $("#carTable").dataTable().fnClearTable();
                initTable();
           }
        });
        

        
    });
    
    
}


/*
    参数解释：
    title   标题
    url     请求的url
    id      需要操作的数据id
    w       弹出层宽度（缺省调默认值）
    h       弹出层高度（缺省调默认值）
*/
/*管理员-增加*/
function car_add(title,url,w,h){
    layer_show(title,url,w,h);
}
/*管理员-删除*/
function car_del(obj,carid){
    layer.confirm('确认要删除吗？',function(index){
        //此处请求后台程序，下方是成功后的前台处理……        
        
        $.ajax({
           type: "post",
           url: "/delCar",
           data: "carid="+carid,
           success: function(msg){
                $("#carTable").dataTable().fnClearTable();
                initTable();
           }
        });
        
        
        $(obj).parents("tr").remove();
        layer.msg('已删除!',{icon:1,time:1000});
    });
}



/*管理员-编辑*/
function car_edit(title,url,id,w,h){
    layer_show(title,url,w,h);
}
/*管理员-停用*/
function car_stop(obj,id){
    layer.confirm('确认要停用吗？',function(index){
        //此处请求后台程序，下方是成功后的前台处理……
        
        $.ajax({
           type: "POST",
           url: "/setUserState",
           data: "userid="+id+"&isabled=0",
           success: function(msg){
                $("#userListTable").dataTable().fnClearTable();
                initTable();
           }
        });
        
        $(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_start(this,id)" href="javascript:;" title="启用" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;</i></a>');
        $(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">已禁用</span>');
        $(obj).remove();
        layer.msg('已停用!',{icon: 5,time:1000});
    });
}

/*管理员-启用*/
function admin_start(obj,id){
    layer.confirm('确认要启用吗？',function(index){
            
        
        $.ajax({
           type: "POST",
           url: "/setUserState",
           data: "userid="+id+"&isabled=1",
           success: function(msg){
                $("#userListTable").dataTable().fnClearTable();
                initTable();
           }
        });
        
        
        //$(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_stop(this,id)" href="javascript:;" title="停用" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;</i></a>');
        //$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
        //$(obj).remove();
        layer.msg('已启用!', {icon: 6,time:1000});
    });
}
</script>
</body>
</html>